package com.kingyea.app.market.utils;

import com.alibaba.fastjson.JSON;
import org.springframework.util.StringUtils;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 日期工具
 *
 * @author Mr.Lin
 * @version v1.0.0
 * @description
 * @date Created in 2017/11/22 17:37
 */
public class DateUtils {

    /**
     * yyyy-MM-dd
     */
    public static final String YYYYMMDD_HYPHEN_SHORT = "yyyy-MM-dd";
    /**
     * yyyy-MM-dd HH:mm:ss
     */
    public static final String YYYYMMDD_HYPHEN_LONG = "yyyy-MM-dd HH:mm:ss";
    /**
     * yyyy/MM/dd
     */
    public static final String YYYYMMDD_SLASH_SHORT = "yyyy/MM/dd";
    /**
     * yyyy/MM/dd HH:mm:ss
     */
    public static final String YYYYMMDD_SLASH_LONG = "yyyy/MM/dd HH:mm:ss";
    /**
     * yyyyMMdd
     */
    public static final String YYYYMMDD = "yyyyMMdd";
    /**
     * yyyyMMddHHmmss
     */
    public static final String YYYYMMDDHHMMSS = "yyyyMMddHHmmss";
    /**
     * yyyy-MM-dd'T'HH:mm:ss.SSSZ
     */
    public static final String YYYYMMDD_HYPHEN_LONG_UTC = "yyyy-MM-dd'T'HH:mm:ss.SSSZ";
    /**
     * EEE, dd MMM yyyy HH:mm:ss zzz
     */
    public static final String SYS_DEFAULT_1 = "EEE, dd MMM yyyy HH:mm:ss zzz";
    /**
     * EEEEEE, dd-MMM-yy HH:mm:ss zzz
     */
    public static final String SYS_DEFAULT_2 = "EEEEEE, dd-MMM-yy HH:mm:ss zzz";
    /**
     * EEE MMMM d HH:mm:ss yyyy
     */
    public static final String SYS_DEFAULT_3 = "EEE MMMM d HH:mm:ss yyyy";
    /**
     * EEE MMM dd HH:mm:ss z yyyy
     */
    public static final String SYS_DEFAULT_4 = "EEE MMM dd HH:mm:ss z yyyy";
    /**
     * reg: yyyy-MM-dd
     */
    public static final String FORMAT4YYYYMMDD_HYPHEN_SHORT = "((19|20)[0-9]{2})-(0?[1-9]|1[012])-(0?[1-9]|[1-2][0-9]|3[01])";
    /**
     * reg: yyyy-MM-dd HH:mm:ss
     */
    public static final String FORMAT4YYYYMMDD_HYPHEN_LONG = "((19|20)[0-9]{2})-(0?[1-9]|1[012])-(0?[1-9]|[1-2][0-9]|3[01])" + " ([01]?[0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]";
    /**
     * reg: yyyy/MM/dd
     */
    public static final String FORMAT4YYYYMMDD_SLASH_SHORT = "((19|20)[0-9]{2})/(0?[1-9]|1[012])/(0?[1-9]|[1-2][0-9]|3[01])";
    /**
     * reg: yyyy/MM/dd HH:mm:ss
     */
    public static final String FORMAT4YYYYMMDD_SLASH_LONG = "((19|20)[0-9]{2})/(0?[1-9]|1[012])/(0?[1-9]|[1-2][0-9]|3[01])" + " ([01]?[0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]";
    /**
     * reg: yyyyMMdd
     */
    public static final String FORMAT4YYYYMMDD = "((19|20)[0-9]{2})(0[1-9]|1[012])(0[1-9]|[1-2][0-9]|3[01])";
    /**
     * reg: yyyyMMddHHmmss
     */
    public static final String FORMAT4YYYYMMDDHHMMSS = "((19|20)[0-9]{2})(0[1-9]|1[012])(0[1-9]|[1-2][0-9]|3[01])" + "([01][0-9]|2[0-3])[0-5][0-9][0-5][0-9]";
    /**
     * reg: yyyy-MM-dd'T'HH:mm:ss.SSSZ
     */
    public static final String FORMAT4YYYYMMDD_HYPHEN_LONG_UTC = "((19|20)[0-9]{2})-(0?[1-9]|1[012])-(0?[1-9]|[1-2][0-9]|3[01])" + "T\\d\\d:\\d\\d:\\d\\d.\\d\\d\\dZ";
    /**
     * reg: EEE, dd MMM yyyy HH:mm:ss zzz  Mon, 01 Jan 2018 20:31:33 CST
     */
    public static final String FORMAT4SYS_DEFAULT_1 = "([A-Za-z]{3}), (0?[1-9]|[1-2][0-9]|3[01]) ([A-Za-z]{3}) ((19|20)[0-9]{2}) ([01]?[0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9] [A-Za-z]{3}";
    /**
     * reg: EEEEEE, dd-MMM-yy HH:mm:ss zzz  Monday, 01-Jan-18 20:31:33 CST
     */
    public static final String FORMAT4SYS_DEFAULT_2 = "([A-Za-z]{6}), (0?[1-9]|[1-2][0-9]|3[01])-([A-Za-z]{3})-([0-9]{2}) ([01]?[0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9] [A-Za-z]{3}";
    /**
     * reg: EEE MMMM d HH:mm:ss yyyy  Mon January 1 20:31:33 2018
     */
    public static final String FORMAT4SYS_DEFAULT_3 = "([A-Za-z]{3}) ([A-Za-z]{4}) ([A-Za-z]|[0-9]{1,2}) ([01]?[0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9] ((19|20)[0-9]{2})";
    /**
     * reg: EEE MMM dd HH:mm:ss z yyyy  Mon Jan 01 20:31:33 CST 2018
     */
    public static final String FORMAT4SYS_DEFAULT_4 = "([A-Z]{1}[a-z]{2}) ([A-Za-z]{3}) (0?[1-9]|[1-2][0-9]|3[01]) ([01]?[0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9] ([A-Za-z]{1,3}) ((19|20)[0-9]{2})";
    private static final List<Map<String, String>> REGULAR_FORMAT_LIST = new ArrayList<>();
    private static final Map<String, Pattern> PATTERN_LIST = new HashMap<>();
    public static Locale DEFAULLOCAL = Locale.US;

    static {
        REGULAR_FORMAT_LIST.add(new HashMap<String, String>() {{
            put(FORMAT4YYYYMMDD_HYPHEN_SHORT, YYYYMMDD_HYPHEN_SHORT);
        }});
        REGULAR_FORMAT_LIST.add(new HashMap<String, String>() {{
            put(FORMAT4YYYYMMDD_HYPHEN_LONG, YYYYMMDD_HYPHEN_LONG);
        }});
        REGULAR_FORMAT_LIST.add(new HashMap<String, String>() {{
            put(FORMAT4YYYYMMDD_SLASH_SHORT, YYYYMMDD_SLASH_SHORT);
        }});
        REGULAR_FORMAT_LIST.add(new HashMap<String, String>() {{
            put(FORMAT4YYYYMMDD_SLASH_LONG, YYYYMMDD_SLASH_LONG);
        }});
        REGULAR_FORMAT_LIST.add(new HashMap<String, String>() {{
            put(FORMAT4YYYYMMDD, YYYYMMDD);
        }});
        REGULAR_FORMAT_LIST.add(new HashMap<String, String>() {{
            put(FORMAT4YYYYMMDDHHMMSS, YYYYMMDDHHMMSS);
        }});
        REGULAR_FORMAT_LIST.add(new HashMap<String, String>() {{
            put(FORMAT4YYYYMMDD_HYPHEN_LONG_UTC, YYYYMMDD_HYPHEN_LONG_UTC);
        }});
        REGULAR_FORMAT_LIST.add(new HashMap<String, String>() {{
            put(FORMAT4SYS_DEFAULT_1, SYS_DEFAULT_1);
        }});
        REGULAR_FORMAT_LIST.add(new HashMap<String, String>() {{
            put(FORMAT4SYS_DEFAULT_2, SYS_DEFAULT_2);
        }});
        REGULAR_FORMAT_LIST.add(new HashMap<String, String>() {{
            put(FORMAT4SYS_DEFAULT_3, SYS_DEFAULT_3);
        }});
        REGULAR_FORMAT_LIST.add(new HashMap<String, String>() {{
            put(FORMAT4SYS_DEFAULT_4, SYS_DEFAULT_4);
        }});

        PATTERN_LIST.put(FORMAT4YYYYMMDD_HYPHEN_SHORT, Pattern.compile(FORMAT4YYYYMMDD_HYPHEN_SHORT));
        PATTERN_LIST.put(FORMAT4YYYYMMDD_HYPHEN_LONG, Pattern.compile(FORMAT4YYYYMMDD_HYPHEN_LONG));
        PATTERN_LIST.put(FORMAT4YYYYMMDD_SLASH_SHORT, Pattern.compile(FORMAT4YYYYMMDD_SLASH_SHORT));
        PATTERN_LIST.put(FORMAT4YYYYMMDD_SLASH_LONG, Pattern.compile(FORMAT4YYYYMMDD_SLASH_LONG));
        PATTERN_LIST.put(FORMAT4YYYYMMDD, Pattern.compile(FORMAT4YYYYMMDD));
        PATTERN_LIST.put(FORMAT4YYYYMMDDHHMMSS, Pattern.compile(FORMAT4YYYYMMDDHHMMSS));
        PATTERN_LIST.put(FORMAT4YYYYMMDD_HYPHEN_LONG_UTC, Pattern.compile(FORMAT4YYYYMMDD_HYPHEN_LONG_UTC));
        PATTERN_LIST.put(FORMAT4SYS_DEFAULT_1, Pattern.compile(FORMAT4SYS_DEFAULT_1));
        PATTERN_LIST.put(FORMAT4SYS_DEFAULT_2, Pattern.compile(FORMAT4SYS_DEFAULT_2));
        PATTERN_LIST.put(FORMAT4SYS_DEFAULT_3, Pattern.compile(FORMAT4SYS_DEFAULT_3));
        PATTERN_LIST.put(FORMAT4SYS_DEFAULT_4, Pattern.compile(FORMAT4SYS_DEFAULT_4));
    }


    /**
     * 自动匹配日期格式
     *
     * @param dateStr
     * @return 返回日期格式字符串 format
     * @author Mr.Lin
     * @date 2017/12/6 14:45
     */
    public static String autoMatchingDateFormat(String dateStr) {
        return autoMatchingDateFormat(dateStr, 0);
    }

    /**
     * 自动匹配日期格式
     *
     * @param dateStr
     * @param index
     * @return java.lang.String
     * @author Mr.Lin
     * @date 2017/12/6 14:45
     */
    private static String autoMatchingDateFormat(String dateStr, Integer index) {
        Integer size = REGULAR_FORMAT_LIST.size();
        if (!StringUtils.isEmpty(dateStr) && index < size) {
            Map<String, String> map = REGULAR_FORMAT_LIST.get(index);
            String key = map.keySet().iterator().next();
            Pattern pattern = PATTERN_LIST.containsKey(key) ? PATTERN_LIST.get(key) : Pattern.compile(key);
            Matcher matcher = pattern.matcher(dateStr);
            return matcher.matches() ? map.get(key) : autoMatchingDateFormat(dateStr, ++index);
        }
        return null;
    }

    /**
     * 把符合日期格式的字符串转换为日期类型-自动识别
     *
     * @param dateStr
     * @return java.util.Date
     * @author Mr.Lin
     * @date 2017/12/11 21:46
     */
    public static Date string2Date(String dateStr) throws Exception {
        return string2Date(dateStr, DEFAULLOCAL);
    }

    /**
     * 把符合日期格式的字符串转换为日期类型-地区
     *
     * @param dateStr
     * @return java.util.Date
     * @author Mr.Lin
     * @date 2017/12/11 21:46
     */
    public static Date string2Date(String dateStr, Locale locale) throws Exception {
        String format = autoMatchingDateFormat(dateStr);
        if (!StringUtils.isEmpty(dateStr) && StringUtils.isEmpty(format)) {
            if (!StringUtils.isEmpty(dateStr) && dateStr.indexOf("-") == -1 && dateStr.indexOf("/") == -1 && (dateStr.length() == 10 || dateStr.length() == 13)) {
                //匹配 10位或者13位 纯数字时间戳
                String format10_13 = "^[1-9]([0-9]{9}|[0-9]{12})$";
                if (Pattern.compile(format10_13).matcher(dateStr).matches()) {
                    return new Date(new Long(dateStr));
                } else {
                    throw new Exception(" 未知的时间格式:" + dateStr);
                }
            } else {
                throw new Exception(" 未知的时间格式:" + dateStr);
            }
        } else {
            return string2Date(dateStr, format, locale == null ? DEFAULLOCAL : locale);
        }
    }

    /**
     * 把符合日期格式的字符串转换为日期类型-需要提供格式化字符串
     *
     * @param dateStr
     * @param format
     * @return java.util.Date
     * @author Mr.Lin
     * @date 2017/12/11 21:46
     */
    @Deprecated
    public static Date string2Date(String dateStr, String format) {
        return string2Date(dateStr, format, null);
    }

    /**
     * 把符合日期格式的字符串转换为日期类型-需要提供格式化字符串-地区
     *
     * @param dateStr
     * @param format
     * @return java.util.Date
     * @author Mr.Lin
     * @date 2017/12/11 21:46
     */
    @Deprecated
    public static Date string2Date(String dateStr, String format, Locale locale) {
        Date d = null;
        try {
            SimpleDateFormat formater;
            if (StringUtils.isEmpty(dateStr) && StringUtils.isEmpty(format)) {
                return null;
            } else if (dateStr.lastIndexOf("Z") != -1) {// Z 跟 UTC 是对应的
                dateStr = dateStr.replace("Z", " UTC");
                formater = new SimpleDateFormat(format);
            } else {
                formater = new SimpleDateFormat(format, locale == null ? DEFAULLOCAL : locale);
            }
            formater.setLenient(false);
            d = formater.parse(dateStr);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return d;
    }

    /**
     * 把日期转换成字符串
     */
    public static String date2String(Date date) {
        return date2String(date, null, null);
    }

    /**
     * 把日期转换成字符串-地区
     */
    public static String date2String(Date date, Locale locale) {
        return date2String(date, null, locale);
    }

    /**
     * 把日期转换成字符串
     */
    public static String date2String(Date date, String format) {
        return date2String(date, format, null);
    }

    /**
     * 把日期转换成字符串
     */
    public static String date2String(Date date, String format, Locale locale) {
        String dateStr = null;
        SimpleDateFormat formater = new SimpleDateFormat(format == null ? YYYYMMDD_SLASH_LONG : format, locale == null ? DEFAULLOCAL : locale);
        try {
            dateStr = formater.format(date);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return dateStr;
    }

    /**
     * 获取两个日期之间有多少个月
     * 包括这两个日期中的月份,忽略日和时间
     *
     * @param startDate
     * @param endDate
     * @return java.util.Date
     * @author Mr.Lin
     * @date 2018/01/05 00:02
     */
    public static List<String> getMonthBetween(String startDate, String endDate) throws Exception {
        return getMonthBetween(string2Date(startDate), string2Date(endDate));
    }

    /**
     * 获取两个日期之间有多少个月
     * 包括这两个日期中的月份,忽略日和时间
     *
     * @param startDate
     * @param endDate
     * @return java.util.Date
     * @author Mr.Lin
     * @date 2018/01/05 00:02
     */
    public static List<String> getMonthBetween(Date startDate, Date endDate) throws Exception {
        List<String> result = new ArrayList<>();
        SimpleDateFormat sdf = new SimpleDateFormat(YYYYMMDD_HYPHEN_SHORT);
        Calendar min = Calendar.getInstance();
        Calendar max = Calendar.getInstance();
        min.setTime(startDate);
        min.set(min.get(Calendar.YEAR), min.get(Calendar.MONTH), 1);
        max.setTime(endDate);
        max.set(max.get(Calendar.YEAR), max.get(Calendar.MONTH), 2);
        Calendar curr = min;
        while (curr.before(max)) {
            result.add(sdf.format(curr.getTime()));
            curr.add(Calendar.MONTH, 1);
        }
        return result;
    }

    /**
     * 下一天
     *
     * @param date
     * @return java.util.Date
     * @author Mr.Lin
     * @date 2017/12/4 19:27
     */
    public static Date nextDate(Date date) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.add(Calendar.DAY_OF_MONTH, +1);
        date = calendar.getTime();
        return date;
    }

    /**
     * 验证时间字符串格式输入是否正确 暂时只支持：yyyy-MM-dd HH:mm:ss
     *
     * @param timeStr
     * @return
     */
    public static boolean valiDateTimeWithLongFormat(String timeStr) {
        String format = "((19|20)[0-9]{2})-(0?[1-9]|1[012])-(0?[1-9]|[12][0-9]|3[01]) " + "([01]?[0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]";
        Matcher matcher = Pattern.compile(format).matcher(timeStr);
        if (matcher.matches()) {
            matcher = Pattern.compile("(\\d{4})-(\\d+)-(\\d+).*").matcher(timeStr);
            if (matcher.matches()) {
                int y = Integer.valueOf(matcher.group(1));
                int m = Integer.valueOf(matcher.group(2));
                int d = Integer.valueOf(matcher.group(3));
                if (d > 28) {
                    Calendar c = Calendar.getInstance();
                    c.set(y, m - 1, 1);
                    int lastDay = c.getActualMaximum(Calendar.DAY_OF_MONTH);
                    return (lastDay >= d);
                }
            }
            return true;
        }
        return false;
    }


    /**
     * 获取当前时间的上一个月度预定日期（start,end）
     *
     * @param
     * @return
     * @author
     * @date
     */
    public static Map getPreReserveDates(Date now) {
        Map<String, Date> map = new HashMap<>();
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(now);
        Integer month = calendar.get(Calendar.MONTH) + 1;
        if (month % 2 == 0) {
            calendar.add(Calendar.MONTH, -2);// 月份减2
        } else {
            calendar.add(Calendar.MONTH, -1);// 月份减1
        }
        calendar.set(Calendar.HOUR_OF_DAY, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.MILLISECOND, 0);
        calendar.set(Calendar.DATE, 1);
        map.put("end", calendar.getTime());
        calendar.add(Calendar.MONTH, -1);// 月份减1
        map.put("start", calendar.getTime());
        return map;

    }

    public static void main(String[] args) throws Exception {
//        String dateStr = "2017-11-27T16:00:00.000Z";
//        System.out.println(string2Date(dateStr,YYYYMMDD_HYPHEN_LONG_UTC));
//        System.out.println(new Date());
//        System.out.println(nextDate(new Date()));
//        String reg1 = "/^((?:19|20)\\d\\d)(0[1-9]|1[012])(0[1-9]|[1-2][0-9]|3[01])$/";
//        String reg2 = "/^((?:19|20)\\d\\d)/(0[1-9]|1[012])/(0[1-9]|[1-2][0-9]|3[01])$/";
//        String reg3 = "/^((?:19|20)\\d\\d)-(0[1-9]|1[012])-(0[1-9]|[1-2][0-9]|3[01])$/";
//        String reg4 = "/^((?:19|20)\\d\\d)-(0[1-9]|1[012])-(0[1-9]|[1-2][0-9]|3[01])$/";
//
//
//        System.out.println(valiDateTimeWithLongFormat("2016-5-2 08:02:02"));
//        System.out.println(valiDateTimeWithLongFormat("2016-02-29 08:02:02"));
//        System.out.println(valiDateTimeWithLongFormat("2015-02-29 08:02:02"));
//        System.out.println(valiDateTimeWithLongFormat("2016-02-02"));
//        System.out.println(valiDateTimeWithLongFormat("2016-02-02 082:02"));

//        String format = "((19|20)[0-9]{2})-(0?[1-9]|1[012])-(0?[1-9]|[1-2][0-9]|3[01]) " + "([01]?[0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]";//2016-5-2 08:02:02
//        String format = "((19|20)[0-9]{2})-(0?[1-9]|1[012])-(0?[1-9]|[1-2][0-9]|3[01])";//2016-5-2
//        String format = "((19|20)[0-9]{2})(0[1-9]|1[012])(0[1-9]|[1-2][0-9]|3[01])";//20160522
//        String format = "((19|20)[0-9]{2})/(0?[1-9]|1[012])/(0?[1-9]|[1-2][0-9]|3[01])";//2016/05/02
//        String format = "((19|20)[0-9]{2})-(0?[1-9]|1[012])-(0?[1-9]|[1-2][0-9]|3[01])" + "T\\d\\d:\\d\\d:\\d\\d.\\d\\d\\dZ";//2017-11-27T16:00:00.000Z

//        Pattern pattern = Pattern.compile(format);
//        Matcher matcher = pattern.matcher("2016-5-2 08:02:02");
//        Matcher matcher = pattern.matcher("2016-5-2");
//        Matcher matcher = pattern.matcher("20160522");
//        Matcher matcher = pattern.matcher("2017/11/27");
//        Matcher matcher = pattern.matcher("2017-11-27T16:00:00.000Z");

//        System.out.println(matcher.matches());

//        for (String s : REGULAR_FORMAT_LIST) {
//            System.out.println(s);
//        }

//        System.out.println(autoMatchingDateFormat("2017-11-27T16:00:00.000Z"));
//        System.out.println(autoMatchingDateFormat("2016-5-2 08:02:02"));
//        System.out.println(autoMatchingDateFormat("2016-5-2"));
//        System.out.println(autoMatchingDateFormat("20160522"));
//        System.out.println(autoMatchingDateFormat("20160522080202"));
//        System.out.println(autoMatchingDateFormat("2017/11/27"));
//        System.out.println(autoMatchingDateFormat("2017/11/27 08:02:02"));
//
//
        System.out.println(string2Date("2017-05-27T08:00:00.000Z"));
        System.out.println(string2Date("2017-5-27 08:02:02"));
        System.out.println(string2Date("2017-5-27"));
        System.out.println(string2Date("20170527"));
        System.out.println(string2Date("20170527080202"));
        System.out.println(string2Date("2017/05/27"));
        System.out.println(string2Date("2017/05/27 08:02:02"));

//        System.out.println(valiDateTimeWithLongFormat("2017-5-27 08:02:02"));
//
//        String format2 = "^[1-9]([0-9]{9}|[0-9]{12})$";//匹配10位或者13位时间戳
//        String time1 = "1512998258";
//        String time2 = "1503934668000";
//        System.out.println(Pattern.compile(format2).matcher(time1).matches());
//        System.out.println(Pattern.compile(format2).matcher(time2).matches());
//        System.out.println(autoMatchingDateFormat(time1));

        // EEE, dd MMM yyyy HH:mm:ss zzz
        // EEEEEE, dd-MMM-yy HH:mm:ss zzz
        // EEE MMMM d HH:mm:ss yyyy
        SimpleDateFormat dateFormat = new SimpleDateFormat(YYYYMMDD_HYPHEN_LONG, Locale.SIMPLIFIED_CHINESE);
//        System.out.println(dateFormat.format(new Date()));
//        System.out.println("EEE MMM dd HH:mm:ss z yyyy"+" >>>1 "+dateFormat.parse("Thu Aug 08 09:16:52 CST 2013"));
//
//        dateFormat = new SimpleDateFormat(YYYYMMDD_HYPHEN_LONG,Locale.CHINA);
//        System.out.println(dateFormat.format(new Date()));
//        System.out.println(YYYYMMDD_HYPHEN_LONG+" >>>2 "+dateFormat.parse("2017-12-12 12:12:12"));
//
//        dateFormat = new SimpleDateFormat(YYYYMMDD_HYPHEN_LONG,Locale.US);
//        System.out.println(dateFormat.format(new Date()));
//        System.out.println(YYYYMMDD_HYPHEN_LONG+" >>>3 "+dateFormat.parse("2017-12-12 12:12:12"));
//
//        System.out.println(string2Date("Thu Aug 08 09:16:52 CST 2013"));

        System.out.println(dateFormat.parse("2017-12-12 12:12:12"));
        System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>");
        DateFormat formatter = new SimpleDateFormat(SYS_DEFAULT_1, Locale.SIMPLIFIED_CHINESE);
        System.out.println(formatter.format(dateFormat.parse("2017-12-12 12:12:12")));
        formatter = new SimpleDateFormat(SYS_DEFAULT_2, Locale.SIMPLIFIED_CHINESE);
        System.out.println(formatter.format(dateFormat.parse("2017-12-12 12:12:12")));
        formatter = new SimpleDateFormat(SYS_DEFAULT_3, Locale.SIMPLIFIED_CHINESE);
        System.out.println(formatter.format(dateFormat.parse("2017-12-12 12:12:12")));
        formatter = new SimpleDateFormat(SYS_DEFAULT_4, Locale.SIMPLIFIED_CHINESE);
        System.out.println(formatter.format(dateFormat.parse("2017-12-12 12:12:12")));


        //Tue Nov 28 00:00:00 CST 2017
        SimpleDateFormat dateFormat1 = new SimpleDateFormat(SYS_DEFAULT_4, Locale.SIMPLIFIED_CHINESE);
        dateFormat1.setLenient(false);
        System.out.println("----" + dateFormat1.format(new Date()));

        System.out.println(System.currentTimeMillis());

        System.out.println(string2Date("1514908800000"));

        System.out.println(JSON.toJSONString(getMonthBetween("2017/01/30 12:12:12", "2018/03/30 12:12:12")));
        System.out.println(JSON.toJSONString(getMonthBetween("1514736000000", "1514736000000")));
        System.out.println(JSON.toJSONString(getMonthBetween("2018/03/30 12:12:12", "2017/01/30 12:12:12")));

        System.out.println(date2String(string2Date("2018-02-28T16:00:00.000Z"), YYYYMMDD_HYPHEN_SHORT));


//        String s = "2016-04-13T16:00:00.000 UTC";
        String s = "2018-02-28T16:00:00.000 UTC";
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
        try {
            Date d = df.parse(s);
            System.out.println(d);
        } catch (Exception e) {
            e.printStackTrace();
        }


        System.out.println(JSON.toJSONString(getPreReserveDates(string2Date("2018/02/23"))));
        ;
        System.out.println(JSON.toJSONString(getPreReserveDates(string2Date("2017/12/23"))));
        ;
        System.out.println(JSON.toJSONString(getPreReserveDates(string2Date("2017/11/23"))));
        ;
        System.out.println(JSON.toJSONString(getPreReserveDates(string2Date("2018/03/23"))));
        ;

        System.out.println(string2Date("2018-06-06 18:45:52"));


    }


}